jQuery.cookie = function(b, j, m) {
    if (typeof j != "undefined") {
        m = m || {};
        if (j === null) {
            j = "";
            m.expires = -1
        }
        var e = "";
        if (m.expires && (typeof m.expires == "number" || m.expires.toUTCString)) {
            var f;
            if (typeof m.expires == "number") {
                f = new Date();
                f.setTime(f.getTime() + (m.expires * 24 * 60 * 60 * 1000))
            } else {
                f = m.expires
            }
            e = "; expires=" + f.toUTCString()
        }
        var l = m.path ? "; path=" + m.path : "";
        var g = m.domain ? "; domain=" + m.domain : "";
        var a = m.secure ? "; secure" : "";
        document.cookie = [b, "=", encodeURIComponent(j), e, l, g, a].join("")
    } else {
        var d = null;
        if (document.cookie && document.cookie != "") {
            var k = document.cookie.split(";");
            for (var h = 0; h < k.length; h++) {
                var c = jQuery.trim(k[h]);
                if (c.substring(0, b.length + 1) == (b + "=")) {
                    d = decodeURIComponent(c.substring(b.length + 1));
                    break
                }
            }
        }
        return d
    }
};
$(function($) {
    if ($.cookie("mod") != null) {
        moddata = eval("(" + $.cookie("mod") + ")")
    } else {
        $.cookie("mod", '{ "data": [{ "mod": "0", "stuats":"1" ,"idx":"0","tit":"理财统计"},{ "mod": "1", "stuats":"1","idx":"1","tit":"我的借款"},{ "mod": "2", "stuats":"1","idx":"2","tit":"投标概况"},{ "mod": "3", "stuats":"1","idx":"4","tit":"认证信息"},{ "mod": "4", "stuats":"1","idx":"4","tit":"待回款"},{ "mod": "5", "stuats":"1","idx":"5","tit":"安全信息"}]}');
        moddata = eval("(" + $.cookie("mod") + ")")
    }
    var load = new vida();
    load.loadmod(moddata);
    $(".open").css("left", $("#modnav").offset().left + $("#modnav").width() - 7);
    $("#add").on("click", function() {
        if ($(this).attr("class") == "acc_add") {
            $(".open").css("width", "246px").css("left", $("#modnav").offset().left + $("#modnav").width() - 165);
            $(".open dd").animate({
                width: "160px"
            }, "fast");
            $(this).addClass("on")
        } else {
            $(".open dd").animate({
                width: "0"
            }, "fast", function() {
                $(".open").css("width", "88px").css("left", $("#modnav").offset().left + $("#modnav").width() - 7)
            });
            $("#add").removeClass("on")
        }
    });
    $(".open").on("mouseleave", function() {
        $(".open dd").animate({
            width: "0"
        }, "fast", function() {
            $(".open").css("width", "88px").css("left", $("#modnav").offset().left + $("#modnav").width() - 7)
        });
        $("#add").removeClass("on")
    });
    $("#con").find("a").bind("click", function() {
        load.add($(this).attr("mod"))
    })
});

$("#modnav").dragsort({
    dragSelector: "div",
    dragBetween: true,
    dragEnd: saveOrder,
    placeHolderTemplate: "<li class='placeHolder'><div></div></li>",
    scrollSpeed: 5
});

function saveOrder() {
    moddata = eval("(" + $.cookie("mod") + ")");
    moddata.data.sort(function(a, b) {
        return a.mod - b.mod
    });
    for (s = 0; s < moddata.data.length; s++) {
        moddata.data[s].idx = $("#mod" + s).parent().attr("data-itemidx")
    }
    moddata = JSON.stringify(moddata);
    $.cookie("mod", moddata)
}
if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(b) {
        var a = this.length;
        if (typeof b != "function") {
            throw new TypeError()
        }
        var d = arguments[1];
        for (var c = 0; c < a; c++) {
            if (c in this) {
                b.call(d, this[c], c, this)
            }
        }
    }
};